﻿using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Piedone.ContentTemplates.Models;

namespace Piedone.ContentTemplates
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable(typeof(TemplatePartRecord).Name,
                table => table
                    .ContentPartRecord()
                    .Column<bool>("IsTemplate")
                    .Column<int>("TemplateId")
            ).AlterTable(typeof(TemplatePartRecord).Name,
                table => table
                    .CreateIndex("IsTemplate", new string[] { "IsTemplate" })
            );


            ContentDefinitionManager.AlterPartDefinition(typeof(TemplatePart).Name,
                builder => builder.Attachable());


            return 1;
        }
    }
}